home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Demos / ByCompany / TipTop_Software / TipTop / Supplement / src / Ascii / AsciiSend1.m < prev    next >
Text File  |  1994-05-08  |  2KB  |  69 lines

  1. /* This script demonstrates a simple transfer protocol which uses a transfer
  2.    progress panel.  This is just like cat.
  3.  
  4. -> File list and file sizes are known.  Example: ZMODEM send.
  5. */
  6. #import "TransferProgressProtocol.h"
  7. #import <libc.h>
  8. #define NOTIFYCHUNK 1024
  9.  
  10. static id remote;
  11.  
  12. /* When user clicks Abort button in the transfer progress panel,
  13.    SIGTERM is sent to the TickleTop process group. */
  14. void transfer_abort(int sig)
  15. {
  16.   [remote transferMessage:"Aborted!"];
  17.   sleep(1);
  18.   [remote transferEnd];
  19.   exit(0);
  20. }
  21.  
  22. int main(int argc, char **argv)
  23. {
  24.   struct stat statbuf;
  25.   int i,j,c;
  26.   FILE *fp;
  27.  
  28.   if(argc<=1) {
  29.     fprintf(stderr,"Usage: %s file ...\n",argv[0]);
  30.     exit(1);
  31.   }
  32. #ifdef __STRICT_BSD__
  33.   signal(SIGTERM,(int*)(int)transfer_abort);
  34. #else
  35.   signal(SIGTERM,(void*)(int)transfer_abort);
  36. #endif
  37.  
  38.   remote=getProgressListener();
  39.   [remote transferBegin:"Ascii Send"];
  40.  
  41.   // Tell TipTop what files we will be transfered:
  42.   for(i=1;i<argc;i++) {
  43.     if(access(argv[i],R_OK)<0 || stat(argv[i],&statbuf)<0) {
  44.       fprintf(stderr,"%s: File %s: %s\n",
  45.           argv[0],argv[i],strerror(cthread_errno()));
  46.       continue;
  47.     }
  48.     [remote transferFile:argv[i] size:statbuf.st_size];
  49.   }
  50.  
  51.   for(i=1;i<argc;i++) {
  52.     if(access(argv[i],R_OK)<0 || stat(argv[i],&statbuf)<0
  53.        || (fp=fopen(argv[i],"r"))==NULL) continue;
  54.  
  55.     [remote transferFileBegin:argv[i]];
  56.     for(j=0;;j++) {
  57.       c=fgetc(fp);
  58.       if(c==EOF) break;
  59.       fputc(c,stdout);
  60.  
  61.       if(j%NOTIFYCHUNK==0) [remote transferProgress:j];
  62.     }
  63.     fclose(fp);
  64.   }
  65.  
  66.   [remote transferEnd];
  67.   exit(0);
  68. }
  69.